#include <system.h>

void write_eeprom(char addr, char data)
{
	char int_on;
	while(test_bit(eecon1, WR))
		;
	eeadr=addr;
	eedata=data;
	clear_bit(eecon1, EEPGD);
	int_on=(test_bit(intcon, GIE));
	clear_bit(intcon, GIE);
	set_bit(eecon1, WREN);
	eecon2=0x55;
	eecon2=0xaa;
	set_bit(eecon1, WR);
	if(int_on)
		set_bit(intcon, GIE);
	clear_bit(eecon1, WREN);
}
char read_eeprom( char addr )
{
	char ret;
    //Read flash
	while(test_bit(eecon1, WR))
		;
    eeadr = addr;
	clear_bit(eecon1, EEPGD);
    set_bit( eecon1, RD );
    asm movf _eedata, W
    asm movwf _ret;
    return(ret);
}
unsigned short read_short_eeprom( char addr )
{
	return((read_eeprom(addr+1)<<8)|read_eeprom(addr));
}
